package mapper;

import entity.Dept;
import entity.Emp;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author JoeZhou
 */
public interface EmpMapper {

    /**
     * 查询所有员工，同时查出员工所在部门信息
     *
     * @return 所有员工及其部门信息
     */
    List<Emp> selectWithDeptByJoin();

    /**
     * 查询所有员工，同时查出员工所在部门信息
     *
     * @return 所有员工及其部门信息
     */
    List<Emp> selectWithDeptBySelect();

    /**
     * 查询所有员工，同时查出员工所在部门信息
     *
     * @return 所有员工及其部门信息
     */
    @Select("select e.empno, e.ename, e.job, e.mgr, e.hiredate, e.sal, e.comm, e.deptno from emp e")
    @Results({
            @Result(column = "empno", property = "empno", id = true),
            @Result(column = "deptno", property = "dept", javaType = Dept.class, jdbcType = JdbcType.INTEGER,
                    one = @One(select = "com.joezhou.mapper.DeptMapper.selectByDeptno")
            )
    })
    List<Emp> selectWithDeptByOne();

}